// src/pages/logout.tsx
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { useUser } from "@/contexts/UserContext";

export default function LogoutPage() {
  const { logout } = useUser();
  const navigate = useNavigate();

  useEffect(() => {
    const performLogout = async () => {
      try {
        await logout();
        // 退出成功后重定向到登录页面
        navigate("/login");
      } catch (error) {
        console.error("Logout failed:", error);
        // 即使退出失败，也重定向到登录页面
        navigate("/login");
      }
    };

    performLogout();
  }, [logout, navigate]);

  return (
    <div className="flex items-center justify-center h-screen">
      <p>正在退出...</p>
    </div>
  );
}